package com.sxjh.common;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class ZPage<T> implements Serializable {

  /**
   * 当前页
   */
  //
  @ApiModelProperty("当前页")
  protected long current = 1;

  /**
   * 每页显示条数，默认 10
   */
  @ApiModelProperty("每页显示条数")
  protected long size = 10;

  /**
   * 数据集合
   */
  @ApiModelProperty("数据集合")
  private List<T> records;

  /**
   * 总数
   */
  @ApiModelProperty("总条数")
  private long total = 0;

  /**
   * 当前分页总页数
   */
  @ApiModelProperty("总页数")
  private long pages;

  @ApiModelProperty("扩展参数")
  private Map<String, Object> extend;

  public ZPage(){

  }

  public ZPage(IPage<T> iPage){
    if(iPage != null){
      this.pages = iPage.getPages();
      this.current = iPage.getCurrent();
      this.size = iPage.getSize();
      this.total = iPage.getTotal();
      this.records = iPage.getRecords() ;
    }
    if (null == this.records || this.records.size() <= 0) {
      this.records = new ArrayList<>();
    }
  }

  public ZPage(IPage<T> iPage, Map<String, Object> extend){
    this(iPage);
    this.extend = extend;
  }

  public Map<String, Object> getExtend() {
    return extend;
  }

  public void setExtend(Map<String, Object> extend) {
    this.extend = extend;
  }

  public List<T> getRecords() {
    return records;
  }

  public long getCurrent() {
    return current;
  }

  public long getPages() {
    return pages;
  }

  public long getSize() {
    return size;
  }

  public long getTotal() {
    return total;
  }

  public void setCurrent(long current) {
    this.current = current;
  }

  public void setPages(long pages) {
    this.pages = pages;
  }

  public void setRecords(List<T> records) {
    this.records = records;
  }

  public void setSize(long size) {
    this.size = size;
  }

  public void setTotal(long total) {
    this.total = total;
  }
}
